import { useCache } from '@/hooks/useCache';
// import { decrypt, encrypt } from '@/utils/jsencrypt';

const { wsCache } = useCache();

const AccessTokenKey = 'ACCESS_TOKEN';
const RefreshTokenKey = 'REFRESH_TOKEN';

// 获取token
export const getAccessToken = () => {
	return wsCache.get(AccessTokenKey);
};

// 设置token
export const setToken = (token: any) => {
	wsCache.set(AccessTokenKey, token);
};

// 删除token
export const removeToken = () => {
	wsCache.clear();
	window.location.href = window.location.href;
};

// 刷新token
export const getRefreshToken = () => {
	return wsCache.get(RefreshTokenKey);
};

// ========== 租户相关 ==========
const TenantIdKey = 'TENANT_ID';
export const getTenantId = () => {
	return wsCache.get(TenantIdKey);
};

export const setTenantId = (username: string) => {
	wsCache.set(TenantIdKey, username);
};

export const removeTenantId = () => {
	wsCache.delete(TenantIdKey);
};

// ========== 账号相关 ==========
const LoginFormKey = 'LOGINFORM';

export type LoginFormType = {
	tenantName: string
	username: string
	password: string
	rememberMe: boolean
}
export const removeLoginForm = () => {
	wsCache.delete(LoginFormKey);
};
